package com.zhongketech.sunflower.utils;

import java.util.ArrayList;
import java.util.List;

import com.zhongketech.sunflower.transport.LogUtil;

import android.app.ActivityManager;
import android.content.Context;


public class Utilities {
	
	private static final String TAG = "Utilities";
	//去掉空格
	public static String replace(String ori)
	{
		String replace = ""; //去空格后的字符串
		String[] str = ori.split(" "); //把原字符串按空格分割
		for(int i = 0;i<str.length;i++)
		{
			if(str[i] != "") 
			{
				replace += str[i]; //
			}
		}

		return replace;
	}

	public static boolean killProcess(String processName,Context context)
	{
		ActivityManager mActivityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);  

		List<ActivityManager.RunningAppProcessInfo> appProcessList = mActivityManager.getRunningAppProcesses();  

		for (ActivityManager.RunningAppProcessInfo appProcess : appProcessList) 
		{  
			LogUtil.i(TAG, "run package: "+appProcess.processName);
			int pid = appProcess.pid; 
			if(appProcess.processName.equals(processName))  
			{
				List<String> cmdList = new ArrayList<String>();
				cmdList.add("kill "+pid);
				try {
					Root.doCmds(cmdList);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				return true;
			}
		} 

		return false;
	}
}
